package edu.calvin.djs32.cs214.interpreters.drivers;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;

import org.antlr.runtime.ANTLRFileStream;
import org.antlr.runtime.RecognitionException;
import org.antlr.runtime.tree.CommonTreeNodeStream;
import org.antlr.runtime.tree.Tree;

import edu.calvin.djs32.cs214.interpreters.frontend.Hobbes2008FrontEnd;
import edu.calvin.djs32.cs214.interpreters.frontend.Hobbes2008TIRBuilder;
import edu.calvin.djs32.cs214.interpreters.prettyprinter.PrettyPrinter;

public class PrettyPrinterCLIDriver {
	private static void generateOutput(PrettyPrinter printer, Tree process) throws IOException, RecognitionException {
		PrintWriter output = new PrintWriter(new BufferedWriter(new FileWriter("output.html")));
		output.println("<html>");
		output.println("<head>");
		output.println("<style type=text/css>");
		output.println(".integer  {color: blue}");
		output.println(".negative  {color: red}");
		output.println(".string  {color: green}");
		output.println("</style>");
		output.println("</head>");
		output.println("<body>");
		output.println(new Hobbes2008TIRBuilder(new CommonTreeNodeStream(process))
        .expression().accept(printer));
		output.println("</body>");
		output.println("</html>");
		output.close();
	}

	public static void main(String[] args) throws IOException, RecognitionException {
		Tree process = new Hobbes2008FrontEnd().process(new ANTLRFileStream("input.hob"));
		PrettyPrinter printer = new PrettyPrinter();		
		generateOutput(printer, process);
	}
}
